<template>
  <div>
    <div class="barchart" :id="main_id"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "Barchart",
  props: {
    datalist: Array,
  },
  data() {
    return {
      main_id:"mian"+Math.random(),
    };
  },
  mounted() {
    //页面加载完成之后要执行的操作放在这里
    this.initEchart();
  },
  methods: {
    initEchart() {
      var chartDom = document.getElementById(this.main_id);
      var myChart1 = echarts.init(chartDom);
      //设置选型option
      var option = {
        title: {
          text: "近一周交易数据",
          subtext: "近七天内的交易总额",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            axisTick: {
              alignWithLabel: true,
            },
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "交易额",
            type: "bar",
            barWidth: "60%",
            data: [5000.54, 52, 12000.52, 334, 390, 330, 220],
          },
        ],
      };
      //绘制图表
      myChart1.setOption(option);
    },
  },
};
</script>

<style>
.barchart {
  width: 500px;
  height: 400px;
}
</style>